// Code file original author: Martin Lapierre, http://devinstinct.com

using System;
using System.Text;
using System.Collections.Generic;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using Microsoft.Practices.EnterpriseLibrary.Validation;
using Microsoft.Practices.EnterpriseLibrary.Validation.Validators;

namespace Microsoft.Practices.EnterpriseLibrary.Validation.Tests.Validators
{
	/// <summary>
	/// Tests <see cref="ObjectValidator"/>.
	/// </summary>
	[TestClass]
	public class ObjectValidatorFixtureGeneric
	{
		[TestMethod]
		public void ReturnsSuccessForValidObject()
		{
			ObjectValidator<TestTarget> validator = new ObjectValidator<TestTarget>();
			ValidationResults validationResults = validator.Validate(new TestTarget("test"));

			Assert.IsTrue(validationResults.IsValid);
		}

		[TestMethod]
		public void ReturnsFailureForInvalidObject()
		{
			ObjectValidator<TestTarget> validator = new ObjectValidator<TestTarget>();
			ValidationResults validationResults = validator.Validate(new TestTarget(null));

			Assert.IsFalse(validationResults.IsValid);
		}

		/// <summary>
		/// Test target for this fixture.
		/// </summary>
		public class TestTarget
		{
			public TestTarget(string value)
			{
				s = value;
			}

			[NotNullValidator()]
			public string s;
		}
	}
}
